﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
using Microsoft.VisualStudio.TestTools.UITesting;
using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
using MouseButtons = System.Windows.Forms.MouseButtons;

namespace MSN
{
    public class MSNFunction
    {
        private Dictionary<string, string> propertyDict = null;
        private string xmlFile = @"D:\Own Projects\CSharp\CodeUI\CodeUI\TestMSN\Data.xml";
        private AppData appData = null;
        public void Login()
        {
            appData = new LoginData(xmlFile);
            appData.InitData("/MSN/Login");
            propertyDict = appData.PropertyDict;
           LoginWindow loginWin = new LoginWindow();

            WinEdit uIEmailaddressEdit = loginWin.EmailAddressEdit;
            WinEdit uIPasswordEdit = loginWin.PasswordEdit;
            WinControl uIStatusMenuButton = loginWin.StatusButton;
            WinMenuItem uIAppearofflineMenuItem = (new StatusMenu(new WinWindow()))[(StatusEnum)Enum.Parse(typeof(StatusEnum), propertyDict["Status"])];//(new TestStatusMenu(loginWin))[StatusEnum.OffLine];
            WinCheckBox uIRemembermyIDandpasswCheckBox = loginWin.RememberIDAndPwdCheckBox;
            WinCheckBox uISignmeinautomaticallCheckBox = loginWin.AutoSingnInCheckBox;
            WinButton uISigninButton = loginWin.SignInButton;            

            // Focus on the email input textbox
            Mouse.Click(uIEmailaddressEdit);

            // Type 'sky_ws@hotmail.com' in 'Email address:' text box
            uIEmailaddressEdit.Text = this.propertyDict["Email"];

            // Type '{Tab}' in 'Email address:' text box
            Keyboard.SendKeys(uIEmailaddressEdit, "{Tab}");//, ModifierKeys.None);

            // Type '********' in 'Password:' text box
            Keyboard.SendKeys(uIPasswordEdit, this.propertyDict["Password"], true);

            // Click 'Status:' MenuButton
            //Mouse.Click(uIStatusMenuButton, new Point(102, 11));
            Mouse.Click(uIStatusMenuButton);

            // Click 'Appear offline' menu item
            Mouse.Click(uIAppearofflineMenuItem);// , new Point(53, 10));

            // Select 'Remember my ID and password' check box
            uIRemembermyIDandpasswCheckBox.Checked = this.propertyDict["RememberIDAndPwd"] == "true";

            // Clear 'Sign me in automatically' check box
            uISignmeinautomaticallCheckBox.Checked = this.propertyDict["AutoSignIn"] == "true";

            // Click 'Sign in' button
            Mouse.Click(uISigninButton);// , new Point(45, 12));
        }
    }
}
